import request from './request'

// 管理员相关接口
export const adminAPI = {
  // 管理员登录
  login: (data) => request.post('/api/admin/login', data),
  // 获取验证码
  getCaptcha: () => request.get('/api/user/captcha', { responseType: 'arraybuffer' })
}

// 用户管理相关接口
export const userAPI = {
  // 获取用户列表
  getList(params) {
    return request.get('/api/admin/user/list', { params })
  },
  // 获取用户详情
  getDetail(id) {
    return request.get(`/api/admin/user/detail/${id}`)
  },
  // 更新用户角色
  updateRole(id, role) {
    return request.put(`/api/admin/user/role/${id}`, { role })
  },
  // 更新用户状态（启用/禁用）
  updateStatus(id, state) {
    return request.put(`/api/admin/user/status/${id}`, { state })
  },
  // 搜索用户
  search(params) {
    return request.get('/api/admin/user/search', { params })
  },
  // 删除用户
  delete(id) {
    return request.delete(`/api/admin/user/delete/${id}`)
  }
}

// 景点管理相关接口
export const scenicAPI = {
  // 获取景点列表
  getAll: (params) => request.get('/api/admin/scenic/list', { params }),
  // 添加景点
  add: (data) => request.post('/api/admin/scenic/put', data),
  // 更新景点
  update: (data) => request.post('/api/admin/scenic/update', data),
  // 删除景点
  delete: (id) => request.get(`/api/admin/scenic/remove/${id}`),
  // 获取景点详情
  getDetail: (id) => request.get(`/api/admin/scenic/detail/${id}`),
  // 搜索景点
  search: (params) => request.get('/api/admin/scenic/search', { params }),
  // 获取景点类型
  getAllTypes: () => request.get('/api/type/all')
}

// 订单管理相关接口
export const orderAPI = {
  // 获取订单列表
  getList: (params) => request.get('/api/admin/ticket/list', { params }),
  // 搜索订单
  search: (params) => request.get('/api/admin/ticket/search', { params }),
  // 获取订单详情
  getDetail: (orderNumber) => request.get('/api/admin/ticket/detail', { params: { orderNumber } }),
  // 取消订单
  cancel: (orderNumber) => request.post('/api/admin/ticket/cancel', JSON.stringify(orderNumber), {
    headers: {
      'Content-Type': 'application/json'
    }
  }),
  // 核销门票
  used: (orderNumber) => request.post('/api/admin/ticket/used', JSON.stringify(orderNumber), {
    headers: {
      'Content-Type': 'application/json'
    }
  }),
  // 根据用户ID获取订单
  getByUserId: (userId) => request.get(`/api/admin/ticket/user/${userId}`),
  // 根据景区ID获取订单
  getByScenicId: (scenicId, params) => request.get(`/api/admin/ticket/scenic/${scenicId}`, { params }),
  // 根据订单状态获取订单
  getByState: (state, params) => request.get(`/api/admin/ticket/state/${state}`, { params })
}

// 博客/动态管理接口
export const blogAPI = {
  // 获取博客列表
  getList: (params) => request.get('/api/admin/blog/list', { params }),
  // 获取博客详情
  getDetail: (id) => request.get(`/api/admin/blog/detail/${id}`),
  // 删除博客
  delete: (id) => request.delete(`/api/admin/blog/remove/${id}`),
  // 根据用户ID获取博客
  getByUserId: (userId) => request.get(`/api/admin/blog/user/${userId}`),
  // 搜索博客
  search: (params) => request.get('/api/admin/blog/search', { params }),
  // 审核博客（设置显示或隐藏）
  audit: (id, status) => request.post(`/api/admin/blog/audit/${id}/${status}`)
}

// 门票核销相关接口
export const ticketAPI = {
  // 门票核销
  verify: (code) => request.post('/api/admin/ticket/used', JSON.stringify(code), {
    headers: {
      'Content-Type': 'application/json'
    }
  }),
  // 获取已核销记录 - 使用状态过滤接口
  getVerified: (params) => request.get('/api/admin/ticket/state/2', { params })
}

// 数据统计相关接口
export const dataAPI = {
  // 获取首页统计数据
  getHomeData: () => request.get('/api/count'),
  // 获取用户增长统计
  getUserGrowth: () => request.get('/api/user/growth'),
  // 获取订单统计
  getOrderStats: () => request.get('/api/count/week'),
  // 获取景点人气排行
  getScenicRanking: () => request.get('/api/scenic/popular')
} 